import tornado
from http_manager import SuccessResponse, FailResponse
from browser_session import BrowserSession

class BaseHandler(tornado.web.RequestHandler):

    # async def aredis_get(self, key):
    #     loop = asyncio.get_event_loop()
    #     return await loop.run_in_executor(None, r_con.get, key)

    browser_session = BrowserSession()

    def __init__(self, *args, **kwargs):
        self.browser_session = BaseHandler.browser_session
        super().__init__(*args, **kwargs)

    def write_error(self, response: FailResponse):
        self.write(response.to_json())

    def write_success(self, response: SuccessResponse):
        self.write(response.to_json())
